package com.loongtech.bi.action.system;

import com.loongtech.bi.action.PageHelper;
import com.loongtech.bi.entity.system.EntityMonitorResult;
import com.loongtech.bi.manager.system.BiMonitorConfigManager;
import com.loongtech.bi.manager.system.BiMonitorResultManager;
import com.loongtech.core.util.Time;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Controller
@Scope("view")
public class BiMonitorResultAction {
	@Resource
	BiMonitorResultManager biMonitorResultManager;
	@Resource
	BiMonitorConfigManager biMonitorConfigManager;

	private List<EntityMonitorResult> list;

	private Date dateStart = new Date(Time.getBeginningOfDay(Time.currentTime()));
	private Date dateEnd = new Date(Time.getEndOfDay(Time.currentTime()));

	@Autowired
	private void inital() {
        searchByCriteria();
	}

	public String dateConvertion(long date) {
		return PageHelper.getDateStr(date);
	}

    public String getDescription(Integer id) {
        return biMonitorConfigManager.get(id) == null ? id + "" : id + "-" + biMonitorConfigManager.get(id).getDescription();
    }

	public String getSubDescription(Integer id) {
		return biMonitorConfigManager.get(id) == null ? "" : biMonitorConfigManager.get(id).getSubDescription();
	}
	
	public void searchByCriteria() {
		list = biMonitorResultManager.searchByCriteria(dateStart, dateEnd);
	}

	public List<EntityMonitorResult> getList() {
		return list;
	}

	public void setList(List<EntityMonitorResult> list) {
		this.list = list;
	}

	public Date getDateStart() {
		return dateStart;
	}

	public void setDateStart(Date dateStart) {
		this.dateStart = dateStart;
	}

	public Date getDateEnd() {
		return dateEnd;
	}

	public void setDateEnd(Date dateEnd) {
		this.dateEnd = dateEnd;
	}

}
